package com.chukun.disruptor.higher.multi;

import com.chukun.disruptor.higher.chain.Trade;
import com.lmax.disruptor.RingBuffer;

/**
 * 生产者
 */
public class TradeProducer {

    private RingBuffer<Trade> ringBuffer;
    public  TradeProducer(RingBuffer<Trade> ringBuffer){
        this.ringBuffer = ringBuffer;
    }

    public void sendData(String id){

        long sequence = ringBuffer.next();
        try {
            Trade trade = ringBuffer.get(sequence);
            trade.setTradeID(id);
        } finally {
            ringBuffer.publish(sequence);
        }

    }

}
